package cn.caixiong.org.service.Impl;

import cn.caixiong.basic.utils.PageList;
import cn.caixiong.org.domain.Employee;
import cn.caixiong.org.mapper.EmployeeMapper;
import cn.caixiong.org.query.BaseQuery;
import cn.caixiong.org.service.IEmployeeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeServiceImpl implements IEmployeeService {
    //注入依赖
    @Autowired
    private EmployeeMapper employeeMapper;
    //新增或修改
    @Override
    public void saveOrUpdata(Employee employee) {
        if (employee.getId()==null){
            employeeMapper.insertSelective(employee);
        }else {
            employeeMapper.updateByPrimaryKeySelective(employee);
        }
    }
    //根据id删除
    @Override
    public void deleteId(Long id) {
        employeeMapper.deleteByPrimaryKey(id);
    }
    //查询所有
    @Override
    public List<Employee> findAll() {
        return employeeMapper.selectAll();
    }
    //根据id查询
    @Override
    public void findOne(Long id) {
        employeeMapper.selectByPrimaryKey(id);
    }
    //分页查询
    @Override
    public PageList<Employee> findPage(BaseQuery query) {
        PageHelper.startPage(query.getPage(),query.getSize());
        List<Employee> employeeList = employeeMapper.selectAll();
        PageInfo<Employee> pageInfo = new PageInfo<>(employeeList);
        //自定义对象
        PageList pageList = new PageList<>(pageInfo.getTotal(),pageInfo.getList());
        return pageList;
    }
    //部门经理
    @Override
    public List<Employee> managerAll() {
        return employeeMapper.managerAll();
    }


}
